/*
 * Copyright By ZATI
 * Copyright By 3a3c88295d37870dfd3b25056092d1a9209824b256c341f2cdc296437f671617
 * All rights reserved.
 *
 * If you are not the intended user, you are hereby notified that any use, disclosure, copying, printing, forwarding or
 * dissemination of this property is strictly prohibited. If you have got this file in error, delete it from your system.
 */

package cn.wzc.crystal.platform.logic;

import cn.wzc.crystal.platform.support.Code;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 逻辑无法继续异常
 * 出现此异常表示: 业务逻辑检查前置条件不允许本次请求正常处理,而非系统代码异常.用户看待异常代码即可做出对应处理.
 */
@Getter
@RequiredArgsConstructor
public class LogicException extends RuntimeException {
	/**
	 * 异常代码
	 */
	private final String code;

	private LogicException(String code, String message) {
		super(message);
		this.code = code;
	}

	/**
	 * 根据代码构建
	 *
	 * @param code 代码
	 * @return 异常实例
	 */
	public static LogicException from(Code code) {
		return new LogicException(code.getCode(), code.getMessage());
	}

	/**
	 * 根据代码和消息构建
	 *
	 * @param code    异常代码
	 * @param message 异常消息
	 * @return 异常实例
	 */
	public static LogicException from(String code, String message) {
		return new LogicException(code, message);
	}

	// 禁止填充堆栈
	@Override
	public synchronized Throwable fillInStackTrace() {
		return this;
	}
}
